<?php

use swap\visitor;

class letter_except extends \swap\service_except {}

class letter_service extends \swap\service {
    
    const number_limit = 5;
    
    public static function can_new_letter() {
        $remained = self::remained_letter();
        if ($remained <= 0) {
            letter_except::throw_prop_msg('letter', '求职信最多创建' . self::number_limit . '份');
        }
    }
    
    public static function remained_letter() {
        $letters = letter_model::get_letters_by_user_id(visitor::get_role_id('user'));
        $number = count($letters);
        return self::number_limit - $number;
    }
    
}